t = codesters.Teacher()
defs = t.find_block('def')
tval2_function = t.find_function('set_background')
tval3_function = t.find_function('disable_floor')
# Is there a function definition? And is it named correctly?
try:
tval1 = defs[0][1]
except:
tval1 = "DNE"
# Is the background set correctly?
try:
tval2 = tval2_function[0][1]
tval2a = t.get_indent_at_line(tval2_function[0][0])
except:
tval2 = "DNE"
tval2a = "DNE"
# Is the floor disabled?
try:
tval3 = tval3_function[0][1]
tval3a = t.get_indent_at_line(tval3_function[0][0])
except:
tval3 = "DNE"
tval3a = "DNE"
t1 = TestObjective()
t1.add_success("set_stage" in tval1, "Great job!")
t1.add_failure(tval1 == "DNE" or tval1 == [], "Did you add a function definition?")
t1.add_failure("set_stage" not in tval1, "Did you change the name of the function?")
t2 = TestObjective()
t2.add_success("soccerfield" in tval2 and tval2a == 4, "Great job!")
t2.add_failure("soccerfield" not in tval2, "Did you set the background to Soccer Field?")
t2.add_failure(tval2a != 4, "Did you indent Soccer Field within set_stage()?")
t2.add_failure(tval2 == "DNE" or tval2a == "DNE", "Did you set the background to Soccer Field?")
t3 = TestObjective()
t3.add_success("stage.disable_floor" in tval3 and tval3a == 4, "Great job!")
t3.add_failure("stage.disable_floor" not in tval3, "Did you add Disable Floor?")
t3.add_failure(tval3a != 4, "Did you indent Disable Floor within set_stage()?")
t3.add_failure(tval3 == "DNE" or tval3a == "DNE", "Did you add Disable Floor inside the function?")
################################################
# Pass test code
# - set pass_required to True if pass is required
# - include tpass before t1 in the test list
pass_required = False
passes = t.find_text("pass")
num_pass_only = 0
for p in passes:
if p[1].lower().replace(' ','') == "pass":
num_pass_only += 1
tpass = TestObjective()
if not pass_required:
tpass.add_success(num_pass_only == 0, "Great job!")
tpass.add_creative(num_pass_only > 0, "Great job! Feel free to delete pass statements now.")
################################################
tester = TestManager()
tester.add_test_list([tpass, t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Enviar Trabajo
-
Actividad Siguiente
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)